/* --------------------------------------------------------
 * Copyright (c) aeky , Inc.  All rights reserved.
 * --------------------------------------------------------
 */
package com.aeky.client.common;

import com.aeky.exception.SessionLostException;
import com.google.gwt.user.client.rpc.AsyncCallback;

/**
 * 自定义rpc callback
 * 
 * @author aeky
 */
public class DefaultCallback<T> implements AsyncCallback<T> {

    private AsyncCallback<T> callback = null;

    public DefaultCallback() {

    }

    public DefaultCallback(AsyncCallback<T> callback) {
        this.callback = callback;
    }

    public void onFailure(Throwable caught) {
        AppParams.getInstance().hideProgressBar();
        if (callback != null) {
            callback.onFailure(caught);
        }
        if (caught instanceof SessionLostException) {
            AppParams.getInstance().showLogin();
            return;
        }
    }

    public void onSuccess(T obj) {
        if (callback != null) {
            callback.onSuccess(obj);
        }
    }

}
